import * as API from '../../api'
import * as types from '../mutation-types'
const state = {
    state: {
      shopList: {
          list: [],
          page: 0,
          total: 0
      },
      shopData: {},
      vipList: []
    },
    mutations: {
      [types.GET_SHOP_LIST_SUCCESS] (state, payload) {
          state.shopList = payload
      },
      [types.GET_SHOP_DATA_SUCCESS] (state, payload) {
          state.shopData = payload
      },
      [types.GET_SHOP_VIP_RECORD_DATA_SUCCESS] (state, payload) {
        state.vipList = payload
    }
    },
    actions: {
      getShopList({commit,state,rootState}, payload) {
          var prom = API.getShopList(payload)
          prom.then(function (data) {
            commit(types.GET_SHOP_LIST_SUCCESS, data.result)
            rootState.reqError = null
          })
          .catch(function (err) {
            rootState.reqError = err
          })
          .finally(function () {
            rootState.reqShake++
          })
          return prom
      },
      getShopDetail({commit,state,rootState}, params) {
        var prom = API.getShopDetail(params)
        prom.then(function (data) {
            commit(types.GET_SHOP_DATA_SUCCESS, data.result)
            rootState.reqError = null
        })
        .catch(function (err) {
          rootState.reqError = err
        })
        .finally(function () {
          rootState.reqShake++
        })
        return prom
      },
      updateShopDetail({commit,state,rootState}, userid) {
        var prom = API.updateShopDetail(userid)
        prom.then(function (data) {
            rootState.reqError = null
        })
        .catch(function (err) {
          rootState.reqError = err
        })
        .finally(function () {
          rootState.reqShake++
        })
        return prom
      },
      updateShopState({commit,state,rootState}, {userid, subid, states}) {
        var prom = API.updateShopState({userid, subid, states})
        prom.then(function (data) {
            rootState.reqError = null
        })
        .catch(function (err) {
          rootState.reqError = err
        })
        .finally(function () {
          rootState.reqShake++
        })
        return prom
      },
      getShopRecord({commit,state,rootState}, userid) {
        var prom = API.getShopRecord(userid)
        prom.then(function (data) {
            commit(types.GET_SHOP_VIP_RECORD_DATA_SUCCESS, data.result)
            rootState.reqError = null
        })
        .catch(function (err) {
          rootState.reqError = err
        })
        .finally(function () {
          rootState.reqShake++
        })
        return prom
      }
    },
    getters: {

    }
}
export default state
